import DList from "@/components/dlist";
export default {
  data() {
    return {
      listData: [],
      loading: false,
      finished: false,
      page: 1,
    };
  },
  activated() {
    this.listData = [];
    this.loading = false;
    this.finished = false;
    this.page = 1;
    this.getData();
  },
  methods: {
    async getData() {
      if (this.loading === true || this.finished === true) {
        return;
      }
      this.loading = true;
      let { data, result, msg } = await $http.post("plugin.stock-service.frontend.controllers.statement.index", { page: this.page });
      if (result === 0) {
        this.$toast(msg);
        return;
      }
      if (data.list.data.length === 0 || data.list.data.length < data.list.per_page || data.list.current_page === data.list.last_page) {
        this.finished = true;
      }
      this.listData.push(...data.list.data);
      this.page++;
      this.loading = false;
    },
    onLoad() {
      this.getData();
    }
  },
  components: {
    DList
  }
};
